package view.component.bonus
{
import core.Language;

import framework.core.AssetsManager;
import framework.view.components.container.RepeaterRenderProxy;
import framework.view.components.graphics.Asset;

import mx.utils.StringUtil;

import framework.utils.TextUtil;

import values.common.BonusValue;
import values.item.ItemGroup;

/**
 * BonusRenderProxy
 * @author jliang
 * 
 */
public class BonusRenderProxy extends RepeaterRenderProxy
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function BonusRenderProxy()
	{
		super();
	}
	//==========================================================================
	//  Variables
	//==========================================================================
	protected var asset:Asset;
	//==========================================================================
	//  Overridden methods: RepeaterRenderProxy
	//==========================================================================
	protected var vo:ItemGroup;
	
	override public function set data(value:*):void
	{
		vo = value;
		
		asset = AssetsManager.loadAsset(vo.template.getIconPathByKey("mid"), iconLoadedHandler);
		
		TextUtil.setText(skin.label, StringUtil.substitute(Language.getText("@bonus_label"), vo.num, vo.template.name));
	}
	
	override public function get data():*
	{
		return vo;
	}
	
	override public function hide():void
	{
		super.hide();
		if (asset)
		{
			if (asset.parent)
			{
				asset.parent.removeChild(asset);
			}
			asset.dispose();
			asset = null;
		}
		TextUtil.setText(skin.label, "");
	}
	
	private function iconLoadedHandler(asset:Asset):void
	{
		skin.iconHolder.addChild(asset);
	}
}
}